CXXFLAGS=-Wall -c -O3
LDFLAGS=-lmysqlclient -lQtGui -lQtCore -lantlr3c

SOURCES_NAMES=main.cpp util.cpp logint.cpp function.cpp program.cpp addtest.cpp C_typesLexer.cpp C_typesParser.cpp antlradapter.cpp tests.cpp
SOURCE_PATH=.
SOURCES=$(patsubst %,$(SOURCES_PATH)/%,$(SOURCES_NAMES))
OBJECTS=$(patsubst %.cpp,$(OBJECT_PATH)/%.o,$(SOURCES_NAMES))
EXECUTABLE=../../BIN/srt_CMD
EXECUTABLE_PATH=../../BIN/
OBJECT_PATH=../../TEMP

all: $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
	$(CXX) $(LDFLAGS) $(OBJECTS) -o $(EXECUTABLE)

$(OBJECT_PATH)/main.o: $(SOURCE_PATH)/main.cpp $(SOURCE_PATH)/logint.cpp $(SOURCE_PATH)/util.cpp $(SOURCE_PATH)/main.h $(SOURCE_PATH)/addtest.h $(SOURCE_PATH)/tests.h
	$(CXX) $(CXXFLAGS) $< -o $@

$(OBJECT_PATH)/util.o: $(SOURCE_PATH)/util.cpp $(SOURCE_PATH)/util.h
	$(CXX) $(CXXFLAGS) $< -o $@

$(OBJECT_PATH)/logint.o: $(SOURCE_PATH)/logint.cpp $(SOURCE_PATH)/util.h $(SOURCE_PATH)/logint.h
	$(CXX) $(CXXFLAGS) -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 $< -o $@

$(OBJECT_PATH)/function.o: $(SOURCE_PATH)/function.cpp $(SOURCE_PATH)/util.h $(SOURCE_PATH)/function.h
	$(CXX) $(CXXFLAGS) $< -o $@

$(OBJECT_PATH)/program.o: $(SOURCE_PATH)/program.cpp $(SOURCE_PATH)/function.h $(SOURCE_PATH)/program.h $(SOURCE_PATH)/util.h $(SOURCE_PATH)/antlradapter.h
	$(CXX) $(CXXFLAGS) $< -o $@

$(OBJECT_PATH)/addtest.o: $(SOURCE_PATH)/addtest.cpp $(SOURCE_PATH)/addtest.h $(SOURCE_PATH)/program.h $(SOURCE_PATH)/function.h $(SOURCE_PATH)/logint.h $(SOURCE_PATH)/antlradapter.h $(SOURCE_PATH)/util.h
	$(CXX) $(CXXFLAGS) $< -o $@

$(OBJECT_PATH)/C_typesLexer.o: $(SOURCE_PATH)/C_typesLexer.cpp $(SOURCE_PATH)/C_typesLexer.h
	$(CXX) $(CXXFLAGS) -lantlr3c $< -o $@

$(OBJECT_PATH)/C_typesParser.o: $(SOURCE_PATH)/C_typesParser.cpp $(SOURCE_PATH)/C_typesParser.h $(SOURCE_PATH)/util.h
	$(CXX) $(CXXFLAGS) -lantlr3c $< -o $@

$(OBJECT_PATH)/antlradapter.o: $(SOURCE_PATH)/antlradapter.cpp $(SOURCE_PATH)/antlradapter.h $(SOURCE_PATH)/C_typesParser.h $(SOURCE_PATH)/C_typesLexer.h
	$(CXX) $(CXXFLAGS) -lantlr3c -I. $< -o $@

$(OBJECT_PATH)/tests.o: $(SOURCE_PATH)/tests.cpp $(SOURCE_PATH)/tests.h $(SOURCE_PATH)/logint.h $(SOURCE_PATH)/program.h $(SOURCE_PATH)/antlradapter.h $(SOURCE_PATH)/util.h
	$(CXX) $(CXXFLAGS) $< -o $@

clean:
	rm -rf $(OBJECTS) $(EXECUTABLE)

debug: CXXFLAGS+=-pg
debug: $(EXECUTABLE)
